package com.crr.common.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    /**
     * 处理跨域请求
     *
     * @param registry
     */
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")//拦截所有请求
                .allowCredentials(false)//不允许携带cookie
                .allowedHeaders("*")//允许所有的请求头
                .allowedOrigins("*")//允许来自所有的域名访问
                .allowedMethods("GET", "POST", "DELETE", "PUT", "", "OPTIONS")//允许哪些方法跨域
                .maxAge(36000);//预检缓存时间
    }
}
